import 'package:flutter/material.dart';

/// Miaoyi UI框架颜色系统
class HColors {
  /// 默认构造函数
  const HColors({
    required this.primary,
    required this.primaryDark,
    required this.primaryLight,
    required this.success,
    required this.successDark,
    required this.successLight,
    required this.info,
    required this.infoDark,
    required this.infoLight,
    required this.warning,
    required this.warningDark,
    required this.warningLight,
    required this.danger,
    required this.dangerDark,
    required this.dangerLight,
    required this.background,
    required this.surface,
    required this.cardBackground,
    required this.divider,
    required this.text,
    required this.textSecondary,
    required this.textDisabled,
    required this.disabledBackground,
    required this.navigationBackground,
    required this.sidebar,
    required this.sidebarHeader,
    
    // 输入框颜色
    required this.inputBorderColor,
    required this.inputFillColor,
    required this.inputDisabledBorderColor,
    required this.inputDisabledFillColor,
    required this.inputDisabledTextColor,
  });

  /// 亮色主题颜色
  factory HColors.light() {
    return const HColors(
      // 主色系列 - 绿色系
      primary: Color(0xFF1AB394),     // Miaoyi框架的主题色
      primaryDark: Color(0xFF18A689), // 主题色悬停/激活色
      primaryLight: Color(0xFF1DC5A3), // 主题色淡化版/禁用色

      // 成功色系列 - 蓝色系
      success: Color(0xFF1C84C6),
      successDark: Color(0xFF1A7BB9),
      successLight: Color(0xFF1A88D4),

      // 信息色系列 - 青色系
      info: Color(0xFF23C6C8),
      infoDark: Color(0xFF21B9BB),
      infoLight: Color(0xFF26D7D9),

      // 警告色系列 - 黄色系
      warning: Color(0xFFF8AC59),
      warningDark: Color(0xFFF7A54A),
      warningLight: Color(0xFFF9B66D),

      // 危险色系列 - 红色系
      danger: Color(0xFFED5565),
      dangerDark: Color(0xFFEC4758),
      dangerLight: Color(0xFFEF6573),

      // 背景色
      background: Color(0xFFF3F3F4),  // 页面背景色
      surface: Colors.white,          // 表面层背景
      cardBackground: Colors.white,   // 卡片背景
      divider: Color(0xFFE7EAEC),     // 分割线颜色

      // 文本色
      text: Color.fromARGB(255, 77, 79, 81),        // 主文本色
      textSecondary: Color(0xFF999C9E), // 次要文本色
      textDisabled: Color(0xFFCCCCCC), // 禁用文本色

      // 其他
      disabledBackground: Color(0xFFE6E6E6), // 禁用背景色
      navigationBackground: Color(0xFF2F4050), // 导航背景色
      
      // 侧边栏颜色
      sidebar: Color(0xFF2F4050),      // 侧边栏背景色
      sidebarHeader: Color(0xFF293846), // 侧边栏头部背景色
      
      // 输入框颜色
      inputBorderColor: Color(0xFFE5E6E7),      // 输入框边框颜色
      inputFillColor: Colors.white,             // 输入框填充颜色
      inputDisabledBorderColor: Color(0xFFD9D9D9), // 禁用输入框边框颜色
      inputDisabledFillColor: Color(0xFFF3F3F3),   // 禁用输入框填充颜色
      inputDisabledTextColor: Color(0xFFBBBBBB),   // 禁用输入框文本颜色
    );
  }

  /// 深色主题颜色
  factory HColors.dark() {
    return const HColors(
      // 主色系列 - 保持与亮色相似以保持品牌一致性
      primary: Color(0xFF1AB394),
      primaryDark: Color(0xFF18A689),
      primaryLight: Color(0xFF1DC5A3),

      // 成功色系列
      success: Color(0xFF1C84C6),
      successDark: Color(0xFF1A7BB9),
      successLight: Color(0xFF1A88D4),

      // 信息色系列
      info: Color(0xFF23C6C8),
      infoDark: Color(0xFF21B9BB),
      infoLight: Color(0xFF26D7D9),

      // 警告色系列
      warning: Color(0xFFF8AC59),
      warningDark: Color(0xFFF7A54A),
      warningLight: Color(0xFFF9B66D),

      // 危险色系列
      danger: Color(0xFFED5565),
      dangerDark: Color(0xFFEC4758),
      dangerLight: Color(0xFFEF6573),

      // 背景色
      background: Color(0xFF2F4050),  // 深色背景
      surface: Color(0xFF293846),     // 深色表面
      cardBackground: Color(0xFF293846), // 深色卡片背景
      divider: Color(0xFF4B5A6A),     // 深色分割线

      // 文本色
      text: Color(0xFFFFFFFF),        // 深色主文本
      textSecondary: Color(0xFFAAAAAA), // 深色次要文本
      textDisabled: Color(0xFF666666), // 深色禁用文本

      // 其他
      disabledBackground: Color(0xFF3A4A5A), // 深色禁用背景
      navigationBackground: Color(0xFF1A2632), // 深色导航背景
      
      // 侧边栏颜色
      sidebar: Color(0xFF1A2632),      // 深色侧边栏背景
      sidebarHeader: Color(0xFF152238), // 深色侧边栏头部背景
      
      // 输入框颜色
      inputBorderColor: Color(0xFF3A4A5A),      // 深色输入框边框颜色
      inputFillColor: Color(0xFF293846),        // 深色输入框填充颜色
      inputDisabledBorderColor: Color(0xFF2A3846), // 深色禁用输入框边框颜色
      inputDisabledFillColor: Color(0xFF1F2A36),   // 深色禁用输入框填充颜色
      inputDisabledTextColor: Color(0xFF666666),   // 深色禁用输入框文本颜色
    );
  }

  /// 根据当前亮暗主题获取对应的颜色
  factory HColors.fromBrightness(Brightness brightness) {
    return brightness == Brightness.light ? HColors.light() : HColors.dark();
  }

  /// 主题色 - #1AB394
  final Color primary;
  
  /// 主题色深色版本（悬停/激活状态）- #18A689
  final Color primaryDark;
  
  /// 主题色淡色版本 - #1DC5A3
  final Color primaryLight;

  /// 成功色 - #1C84C6
  final Color success;
  
  /// 成功色深色版本 - #1A7BB9
  final Color successDark;
  
  /// 成功色淡色版本 - #1A88D4
  final Color successLight;

  /// 信息色 - #23C6C8
  final Color info;
  
  /// 信息色深色版本 - #21B9BB
  final Color infoDark;
  
  /// 信息色淡色版本 - #26D7D9
  final Color infoLight;

  /// 警告色 - #F8AC59
  final Color warning;
  
  /// 警告色深色版本 - #F7A54A
  final Color warningDark;
  
  /// 警告色淡色版本 - #F9B66D
  final Color warningLight;

  /// 危险色 - #ED5565
  final Color danger;
  
  /// 危险色深色版本 - #EC4758
  final Color dangerDark;
  
  /// 危险色淡色版本 - #EF6573
  final Color dangerLight;

  /// 页面背景色 - 亮色模式: #F3F3F4, 暗色模式: #2F4050
  final Color background;
  
  /// 表面层背景色
  final Color surface;
  
  /// 卡片背景色
  final Color cardBackground;
  
  /// 分割线颜色
  final Color divider;

  /// 主文本色
  final Color text;
  
  /// 次要文本色
  final Color textSecondary;
  
  /// 禁用文本色
  final Color textDisabled;

  /// 禁用状态背景色
  final Color disabledBackground;
  
  /// 导航背景色
  final Color navigationBackground;

  /// 侧边栏背景色
  final Color sidebar;
  
  /// 侧边栏头部背景色
  final Color sidebarHeader;

  /// 输入框边框颜色
  final Color inputBorderColor;
  
  /// 输入框填充颜色
  final Color inputFillColor;
  
  /// 禁用输入框边框颜色
  final Color inputDisabledBorderColor;
  
  /// 禁用输入框填充颜色
  final Color inputDisabledFillColor;
  
  /// 禁用输入框文本颜色
  final Color inputDisabledTextColor;

  /// 根据按钮类型获取对应的颜色
  Color getButtonColor(String type) {
    switch (type) {
      case 'primary':
        return primary;
      case 'success':
        return success;
      case 'info':
        return info;
      case 'warning':
        return warning;
      case 'danger':
        return danger;
      case 'white':
        return Colors.white;
      case 'link':
        return Colors.transparent;
      case 'default':
      default:
        return const Color(0xFFE6E6E6); // 默认按钮灰色背景
    }
  }

  /// 根据按钮类型获取对应的悬停/激活状态颜色
  Color getButtonHoverColor(String type) {
    switch (type) {
      case 'primary':
        return primaryDark;
      case 'success':
        return successDark;
      case 'info':
        return infoDark;
      case 'warning':
        return warningDark;
      case 'danger':
        return dangerDark;
      case 'white':
        return const Color(0xFFF9F9F9); // 白色按钮悬停时略微变暗
      case 'link':
        return Colors.transparent;
      case 'default':
      default:
        return const Color(0xFFD9D9D9); // 默认按钮悬停色
    }
  }

  /// 为Material主题创建ColorScheme
  ColorScheme toColorScheme(Brightness brightness) {
    return ColorScheme(
      primary: primary,
      primaryContainer: primaryDark,
      secondary: success,
      secondaryContainer: successDark,
      surface: surface,
      error: danger,
      onPrimary: Colors.white,
      onSecondary: Colors.white,
      onSurface: text,
      surfaceContainerHighest: text,
      onError: Colors.white,
      brightness: brightness,
    );
  }

  /// 复制颜色实例并更新指定的值
  HColors copyWith({
    Color? primary,
    Color? primaryDark,
    Color? primaryLight,
    Color? success,
    Color? successDark,
    Color? successLight,
    Color? info,
    Color? infoDark,
    Color? infoLight,
    Color? warning,
    Color? warningDark,
    Color? warningLight,
    Color? danger,
    Color? dangerDark,
    Color? dangerLight,
    Color? background,
    Color? surface,
    Color? cardBackground,
    Color? divider,
    Color? text,
    Color? textSecondary,
    Color? textDisabled,
    Color? disabledBackground,
    Color? navigationBackground,
    Color? sidebar,
    Color? sidebarHeader,
    Color? inputBorderColor,
    Color? inputFillColor,
    Color? inputDisabledBorderColor,
    Color? inputDisabledFillColor,
    Color? inputDisabledTextColor,
  }) {
    return HColors(
      primary: primary ?? this.primary,
      primaryDark: primaryDark ?? this.primaryDark,
      primaryLight: primaryLight ?? this.primaryLight,
      success: success ?? this.success,
      successDark: successDark ?? this.successDark,
      successLight: successLight ?? this.successLight,
      info: info ?? this.info,
      infoDark: infoDark ?? this.infoDark,
      infoLight: infoLight ?? this.infoLight,
      warning: warning ?? this.warning,
      warningDark: warningDark ?? this.warningDark,
      warningLight: warningLight ?? this.warningLight,
      danger: danger ?? this.danger,
      dangerDark: dangerDark ?? this.dangerDark,
      dangerLight: dangerLight ?? this.dangerLight,
      background: background ?? this.background,
      surface: surface ?? this.surface,
      cardBackground: cardBackground ?? this.cardBackground,
      divider: divider ?? this.divider,
      text: text ?? this.text,
      textSecondary: textSecondary ?? this.textSecondary,
      textDisabled: textDisabled ?? this.textDisabled,
      disabledBackground: disabledBackground ?? this.disabledBackground,
      navigationBackground: navigationBackground ?? this.navigationBackground,
      sidebar: sidebar ?? this.sidebar,
      sidebarHeader: sidebarHeader ?? this.sidebarHeader,
      inputBorderColor: inputBorderColor ?? this.inputBorderColor,
      inputFillColor: inputFillColor ?? this.inputFillColor,
      inputDisabledBorderColor: inputDisabledBorderColor ?? this.inputDisabledBorderColor,
      inputDisabledFillColor: inputDisabledFillColor ?? this.inputDisabledFillColor,
      inputDisabledTextColor: inputDisabledTextColor ?? this.inputDisabledTextColor,
    );
  }
} 